home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
manchest.lha
/
MANCHESTER
/
manchester
/
4.1
/
SUNFunKey.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
8KB
|
276 lines
" NAME SUNFunKey
AUTHOR Mario Wolczko <mario@cs.man.ac.uk>
FUNCTION Binds functions to keys on the SUN type-4 keyboard
ST-VERSION 4.1
PREREQUISITES
CONFLICTS
DISTRIBUTION world
VERSION 1
DATE 27 March 1993
SUMMARY
This goodie binds the usual Again,Undo,Copy,Paste and Cut functions to the keys
with those keysyms on the SUN Type 4 keyboard. (You may need to use xmodmap
to set up the appropriate mappings; a fragment of a suitable file is included below.)
On the numeric pad, Enter is bound to Accept, Home moves to the
beginning of the line, End moves to the end of line, R1, R2 and R3 do
it, print it, and inspect it.
It also binds the LineFeed key to a function that inserts a newline, and copies
indentation from the previous line (this was adapted from a ParcPlace VI2.5
goodie, FunctKey.st).
It should be obvious how to bind other keys following this scheme.
In general:
1. Ensure that your window system is mapping the key to an appropriate key symbol.
If not, use xmodmap to achieve the mapping. xev is a useful program for
finding which keycode is generated by a key.
Names of X11 keysyms can usually be found in /usr/include/X11/keysymdef.h
and InputState class>initKeys.
2. Add a suitable line to ParagraphEditor>initializeSUNkeys to associate the keysym
with a method. Write the method if necessary.
3. Reinitialize ParagraphEditor. New windows will use the new mapping.
Here is a chunk of input for xmodmap:
!! map for SUN Type 4 keyboards (PC like)
!! each code has 2 syms: normal and shifted
!!
!! keys at left of keyboard
!!
!! Stop
keycode 8=L1
!! Again
keycode 10=L2
!! Props
keycode 32=L3
keycode 33=L4
!! Front
keycode 56=L5
!! Copy
keycode 58=L6
!! Open
keycode 79=L7
!! Paste
keycode 80=L8
keycode 102=L9
!! Cut
keycode 104=L10
!!
!! keys at top
keycode 12=F1
keycode 13=F2
keycode 15=F3
keycode 17=F4
keycode 19=F5
keycode 21=F6
keycode 23=F7
keycode 24=F8
keycode 25=F9
keycode 14=F10
!! keysyms F11 and F12 are the same as L1 and L2 in keysymdef.h
!!
!! keys at right
!! Pause R1
keycode 28=R1
!! PrSc R2
keycode 29=R2
!! Scroll Lock Break R3
keycode 30=R3
!! Num Lock
keycode 105=Num_Lock
!! = R4
keycode 52=R4
!! / R5
keycode 53=R5
!! * R6
keycode 54=R6
!! -
!!keycode 78=
!! 7 Home R7
keycode 75=Home
!! 8 Up R8
keycode 76=Up
!! 9 PgUp R9
keycode 77=R9
!! +
!! keycode 132=plus KP_Add
!! 4 Left R10
keycode 98=Left
!! 5 R11
keycode 99=R11
!! 6 Right R12
keycode 100=Right
!! 1 End R13
keycode 119=End
!! 2 Down R14
keycode 120=Down
!! 3 PgDn R15
keycode 121=R15
!! Enter
keycode 97=KP_Enter
!! 0 Ins
keycode 101=Insert
!! . Del
keycode 57=Delete
"
'From Objectworks(r)\Smalltalk, Release 4 of 25 October 1990 on 2 March 1991 at 3:48:42 pm'!
!ParagraphEditor methodsFor: 'editing'!
againKey: aChar
"Repeat the last edit"
self again!
copySelectionKey: aChar
"Copy the current text selection."
self copySelection!
echoInputKey: aCharEvent
"A bizarre character has been received: echo its value to the Transcript, but ignore it otherwise."
Transcript show: 'Unknown key: ',aCharEvent keyValue printString; cr.
self ignoreInputKey: aCharEvent!
indentedCRKey: aChar
"Replace the current text selection with a CR plus
the number of tabs and spaces found at the beginning of
the current line."
"Based on a (rather inefficient) version from ParcPlace."
| text index character characterStream ssi |
"Sniff backwards along text string till CR or beginning of string."
text := self paragraph text.
index := ssi := self selectionStartIndex.
"test for empty text"
index = 1 ifTrue: [self appendToSelection: (String with: CR). ^self].
character := nil.
[index := index - 1.
character := text at: index.
character = CR or: [index = 1]]
whileFalse.
"Special exit for immediate encounter of CR."
(ssi - 1 = index)
ifTrue: [self appendToSelection: (String with: CR). ^self].
"Now accumulate whitespace into characterStream till first non-white
character, or end of string."
characterStream := (String new: 8) writeStream.
characterStream nextPut: CR.
character == CR ifTrue: [index := index + 1].
character := text at: index.
[character = Tab | (character = Space) & (index < ssi)]
whileTrue:
[characterStream nextPut: character.
index := index + 1.
index < ssi ifTrue: [character := text at: index]].
self appendToSelection: characterStream contents!
doItKey: aChar
self doIt!
inspectItKey: aChar
self inspectIt!
printItKey: aChar
self printIt! !
!ParagraphEditor class methodsFor: 'class initialization'!
initialize
"Initialize the yellow button menu information, the keyboard map for special
control characters, and the shared buffers for copying text across views and
managing undo."
"ParagraphEditor initialize."
PreviousSelections := OrderedCollection with: ' ' asText.
self currentSelection: (self undoSelection: Text new).
TextEditorYellowButtonMenu :=
PopUpMenu labels: 'again\undo\copy\cut\paste\accept\cancel' withCRs
lines: #(2 5 )
values: #(again undo copySelection cut paste accept cancel).
CodeYellowButtonMenu :=
PopUpMenu
labelList: #((again undo) (copy cut paste) ('do it' 'print it' 'inspect') (accept cancel) (hardcopy))
values: #(again undo copySelection cut paste doIt printIt inspectIt accept cancel hardcopy).
self initializeDispatchTable.
self initializeSUNKeys.
CompilationErrorSignal := (self errorSignal newSignalMayProceed: true)
notifierString: 'Compilation failed';
nameClass: self message: #compilationErrorSignal.!
initializeDispatchTable
"Initialize the keyboard dispatch table."
"ParagraphEditor initializeDispatchTable."
Keyboard := DispatchTable new.
Keyboard defaultForCharacters: #normalCharacterKey:.
Keyboard defaultForNonCharacters: #echoInputKey:.
Keyboard bindValue: #backspaceKey: to: Cut.
Keyboard bindValue: #pasteKey: to: Paste.
Keyboard bindValue: #backspaceKey: to: BS.
Keyboard bindValue: #backWordKey: to: Ctrlw.
Keyboard bindValue: #displayIfTrueKey: to: Ctrlt.
Keyboard bindValue: #displayIfFalseKey: to: Ctrlf.
Keyboard bindValue: #displayDateKey: to: Ctrld.
Keyboard bindValue: #displayColonEqualKey: to: Ctrlg.
"Keyboard bindValue: #displayCRKey: to: #Enter."
Keyboard bindValue: #cursorUpKey: to: #Up.
Keyboard bindValue: #cursorDownKey: to: #Down.
Keyboard bindValue: #cursorLeftKey: to: #Left.
Keyboard bindValue: #cursorRightKey: to: #Right.
Keyboard bindValue: #homeKey: to: #Home.
Keyboard bindValue: #endKey: to: #End.
Keyboard bindValue: #pageUpKey: to: #PageUp.
Keyboard bindValue: #pageDownKey: to: #PageDown.
'<''"[{(' do:
[:char |
Keyboard
bindValue: #encloseKey:
to: ESC
followedBy: char].
'sSuUbBiIx+-' do:
[:char |
Keyboard
bindValue: #changeEmphasisKey:
to: ESC
followedBy: char].
Keyboard
bindValue: #miniFormatKey:
to: ESC
followedBy: $f.
Keyboard
bindValue: #selectCurrentTypeInKey:
to: ESC
followedBy: Tab.
Keyboard
bindValue: #selectCurrentTypeInKey:
to: #F1!
initializeSUNKeys
"Initialize the mapping for function keys on the SUN type-4 keyboard."
"ParagraphEditor initializeSUNKeys"
Keyboard bindValue: #indentedCRKey: to: LF.
Keyboard bindValue: #againKey: to: #L2.
Keyboard bindValue: #undoKey: to: #L4.
Keyboard bindValue: #copySelectionKey: to: #L6.
Keyboard bindValue: #pasteKey: to: #L8.
Keyboard bindValue: #cutKey: to: #L10.
Keyboard bindValue: #doItKey: to: #R1.
Keyboard bindValue: #printItKey: to: #R2.
Keyboard bindValue: #inspectItKey: to: #R3.
Keyboard bindValue: #acceptKey: to: #Enter.
Keyboard bindValue: #pageUpKey: to: #R9.
Keyboard bindValue: #pageDownKey: to: #R15! !
ParagraphEditor initialize!
TextItemEditor initialize!